<?php 

class AdminCommonPagePresenter extends AdminPresenter{
	
	private $model;
	/**
	 * Start lifecycle presenter
	 *
	 * @return void
	 */
	protected function startup(){
		parent::startup();
		
		$this->model = CommonPageModel::getInstance();
	}

	/**
	 * Settings for all render
	 *
	 * @return void
	 */
	protected function beforeRender(){

	}

	/**
	 * Render default action
	 *
	 * @return void
	 */
	public function renderDefault($id){
		
		// zjistime si id menu
		$menuItem = $this->system->getMenuItemByName($id);

		$info = $this->model->getPageInfo($menuItem[0]["id_menu"]);

		$this->template->add("info", $info[0]);
		$this->template->form = $this->getComponent("page");

	}
	
	public function createComponentPage($id){
		
		$item = $this->system->getMenuItemByname($this->getRequest()->params["id"]);
		$ident = $item[0]["id_menu"];
		
		$info = $this->model->getPageInfo($ident);
		
		$form = new AppForm();
		
		$form->addTextArea("content","Obsah:")->setDefaultValue($info[0]["content"]);
		$form["content"]->getControlPrototype()->class = "editor";
		
		$form->addHidden("id_menu")->setDefaultValue($ident);
		
		$form->addSubmit('confirm', 'Uložit')->getControlPrototype()->class('submit');
		$form->onSubmit[] = array($this, 'PageSubmitted');
		
		return $form;
	}
	
	public function PageSubmitted(AppForm $form){
		
		$values = $form->getValues();
		
		$this->model->savePage($values);
		$this->flashMessage("Obsah stránky byl upraven.", "ok");
		
	}
}

?>